<?php
/**
 * Object Relational Persistence Mapping Class for table: package_test_asso_service
 *
 * @package	com.athena
 * @author	LHV
 */
class PackageTestAssoService extends ORDataObject {

	/**#@+
	 * Fields of table: package_test_asso_service mapped to class members
	 */
	var $package_test_asso_service_id		= '';
	var $package_item_id		= '';
	var $service_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'package_test_asso_service';

	/**
	 * Primary Key
	 */
	var $_key = 'package_test_asso_service_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'PackageTestAssoService';

	/**
	 * Handle instantiation
	 */
	function PackageTestAssoService() {
		parent::ORDataObject();
	}

	public function getServiceInATest($packageItemId) {
		$ds = new Datasource_sql();
		$sql = array(
			'cols'	=> "service_id",
			'from'	=> "$this->_table",
			'where'	=> "package_item_id = $packageItemId"			
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function delete($packageItemId) {
		$sql = "delete from $this->_table where package_item_id = $packageItemId";
		$this->_execute($sql);
	}
	
	public function addItem($packageItemId, $testItem) {
			
		foreach ($testItem as $serviceId) {
			$data = array (
				'package_item_id' 	=> $packageItemId,
				'service_id'		=> $serviceId);
			$or = Celini::newORDO('PackageTestAssoService');
			$or->populateArray($data);			
			$or->persist();
		}
	}
	
	public function listTestService($packageItemId) {
	    $field        =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		
		$ds = new Datasource_sql();
		$sql = array(
			'cols'	=> "S.service_id, S.$field name",
			'from'	=> "$this->_table TI 
				INNER JOIN service S ON TI.service_id = S.service_id",
			'where'	=> "TI.package_item_id = $packageItemId",
			'orderby'	=> "S.name"
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
}
?>
